home *** CD-ROM | disk | FTP | other *** search
/ Learn Microsoft Visual Basic 6.0 Now / Learn Microsoft Visual Basic 6.0 Now (Microsoft Press)(X03-58607)(1998).ISO / media / chap01 / b01d025.cc2 < prev    next >
Text File  |  1998-06-07  |  5KB  |  107 lines

  1. 0, In this demonstration, we'll complete 
  2. 3, the Lucky Seven slot machine by writing 
  3. 5, program code. Program code is written in a 
  4. 7, language called Visual Basic, which 
  5. 9, follows special syntax rules we'll discuss 
  6. 11, throughout this course. You get started 
  7. 13, writing program code by double-clicking 
  8. 15, the object you want to customize. Since 
  9. 17, the user will operate our program by 
  10. 19, clicking the Spin and End buttons, I'll 
  11. 21, write program code for both these buttons. 
  12. 24, And because these buttons will be 
  13. 25, activated by a single click, I'll add the code 
  14. 28, to a special click event procedure for 
  15. 30, each button. When I double-click the End 
  16. 32, button, Visual Basic displays the Code 
  17. 37, window, a special editor for editing 
  18. 39, program code. The Code window contains an 
  19. 41, Object drop-down list box, so you can 
  20. 46, select the object you want to work with. It 
  21. 50, also contains a Procedure drop-down 
  22. 52, list box, so you can select the event you 
  23. 55, want to customize. Private, Sub, and End 
  24. 61, Sub statements mark the beginning and 
  25. 62, ending of a procedure, a block of code 
  26. 65, associated with a particular object or 
  27. 67, task. In this case, we're writing an event 
  28. 70, procedure for the End button. So we'll 
  29. 72, type a program statement called End. End 
  30. 75, is a Visual Basic keyword that tells the 
  31. 77, compiler to stop the program. Now that 
  32. 80, we're finished with this simple event 
  33. 81, procedure, we'll click the Close button and 
  34. 84, prepare to write the code for the Spin 
  35. 86, button, an event procedure that puts 
  36. 89, numbers in the Spin windows, and if the user 
  37. 92, sees a seven, displays a stack of 
  38. 94, coins. We'll double-click the Spin button and 
  39. 99, open the Command1_Click event procedure 
  40. 101, in the Code window. This event 
  41. 104, procedure will hide the coin stack, create three 
  42. 106, random numbers, and check to see if one 
  43. 108, of the numbers is a seven. If a seven 
  44. 111, does appear, the procedure will display 
  45. 113, the coin stack and sound a beep in the 
  46. 115, speaker. Okay, the first line I'll type 
  47. 118, sets the Image1object's Visible property 
  48. 120, to False. After I type the object's name 
  49. 126, and a period, Visual Basic displays a 
  50. 128, list box with all the valid property 
  51. 130, settings for the object. I can either select 
  52. 132, an object from the list or type it out 
  53. 134, myself. When I type an equal sign, Visual 
  54. 143, Basic displays another list box with 
  55. 145, the value of the property setting. I can 
  56. 148, type it out myself or select it from the 
  57. 150, list. Finally, I'll add a comment 
  58. 156, designated by a single quotation mark to 
  59. 159, describe just what this programming statement 
  60. 160, is doing. My comment, "Hide coins," 
  61. 166, won't be executed by the Visual Basic 
  62. 167, compiler, but it's a note that I can look at 
  63. 169, later when I wonder what the program is 
  64. 171, doing. When I press the Enter key, 
  65. 173, Visual Basic puts the comment in green type 
  66. 176, to identify it as a comment that's not 
  67. 178, run by the program. The False keyword is 
  68. 181, also placed in blue type to identify it 
  69. 183, as a keyword that Visual Basic uses. 
  70. 186, Finally, Image1.Visible is in black type. 
  71. 190, Now I'll take a moment to type the rest of 
  72. 192, the program code for the event 
  73. 193, procedure. The final Command1_Click event 
  74. 198, procedure contains ten lines of code. It's a 
  75. 201, little early in the programming course to 
  76. 202, get into the specific details of each 
  77. 203, of these program statements, but I'll 
  78. 205, cover a few of the fine points if you'd 
  79. 207, like. My goal is to get you familiar with 
  80. 209, objects, properties, and the Code window 
  81. 211, and to come back to program statement 
  82. 213, syntax in Chapter 4. In the second, third 
  83. 218, and fourth lines, I'm placing numbers in 
  84. 219, the three Spinner windows in our form. 
  85. 222, I created these with label objects 
  86. 223, earlier, but now I'm assigning values to them 
  87. 225, with program code. The numbers come 
  88. 228, from a special Visual Basic function called 
  89. 230, Rnd, which picks a random number 
  90. 232, between zero and one. I multiply each number 
  91. 235, by ten and use the Int function to create 
  92. 238, an integer value between zero and nine 
  93. 240, for the windows. Next, I check to see if 
  94. 244, a seven appeared in one of the spinner 
  95. 246, windows, using a decision structure 
  96. 248, called If...Then that you'll learn more about 
  97. 251, in Chapter 5. If a seven does appear in 
  98. 257, one of the windows, procedure displays 
  99. 259, the coin stack by setting the Image1 
  100. 261, object's Visible property to True. To bring 
  101. 264, home the point, I'll use the Beep 
  102. 265, statement to sound a note from the computer 
  103. 267, speaker. Now that I've finished typing the 
  104. 270, program, I'll close the Code window and 
  105. 275, use the Save Project As command to save 
  106. 277, the project to disk.
  107. 281, END